#include "net-connection/NetConnection.h"
#include "request/RequestManager.h"
#include <cstdlib>

namespace
{
int getPortFromCommandLine(char **argv)
{
	return atoi(argv[1]);
}

int getDefalutPort()
{
	return 8080;
}

int getPort(int argc, char **argv)
{
	if (argc == 2)
		return getPortFromCommandLine(argv);
	else
		return getDefalutPort();
}
}

int main(int argc, char **argv)
{
	NetConnection connection;

	connection.lisen(getPort(argc, argv));
	while (1)
	{
		int connfd = connection.accept();
		RequestManager(connfd).run();
		connection.close();
	}
}
